<?php
/**
 * @author wyl
 * @date 2015-8-6 15:02:01
 */
Yii::import('system.web.widgets.CWidget');
class CButtons{
	public $title;
	public $click;
	public $class='btn btn-default';
	public $id;
	public $htmlOptions = array();
	
	
	public function buildOptions(){
		$this->htmlOptions['id'] = $this->id;
		$this->htmlOptions['class'] = $this->class;
		return $this;
	}
	
	public function buildJs(){
		$clickJsCode = new CJavaScriptExpression($this->click);
		Yii::app()->clientScript->registerScript($this->id.'-click','
			$("#'.$this->id.'").on("click",'.$clickJsCode.');
		');
	}
	
	public function renderButton(){
		$this->buildOptions();
		$buttonHtml = CHtml::htmlButton($this->title,$this->htmlOptions);
		if (!empty($this->click)) {
			$this->buildJs();
		}
		return $buttonHtml;
	}
	
	
	/*
	public function renderButton(){
		$html="<button type='button' class='".$this->class."'".
		'onclick='.$this->event
		.">".$this->title.'</button>';
		
		return $html;
	}
	*/
}